/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package core.threads.server.creation;

import core.threads.server.Server_Public_Data;
import core.threads.server.Server_Public_MsgBox;
import core.threads.server.Server_Public_Thread;
import myTest.MYTest;
import java.util.ArrayList;

/**
 *
 * @author Invince
 */
public class T_Server_CaraNb_Config  extends Thread{
/*----------Attributs-------------------*/
    protected boolean stop;
    protected boolean suspend;
/*----------Public functions------------*/
    @Override
    public void run() {
        /**-----Init-----**/
        MYTest.println("Thread:T_Server_Cara_Config start");
        int nbPlayer;
        nbPlayer=Server_Public_Data.tempListPlayer.size();
        if(nbPlayer<4){
            MYTest.println("Thread:T_Server_Cara_Config return, cause nbPlayer not sufficient");
            Server_Public_Thread.tServerNewGame.resumeT();  
            this.suspendT();
        }
        //重置tempCarNbConfig
        synchronized(Server_Public_Data.semaTempCaraNbConfig){
            Server_Public_Data.tempCaraNbConfig=new Server_Public_MsgBox.CaraNb_Config();
        }
        /**-----Loop----**/
        while(!this.stop){
            if(!this.suspend){
                if(!Server_Public_MsgBox.msgBox_Server_CaraNb_Config.isEmpty()){
                    synchronized(Server_Public_Data.semaTempCaraNbConfig){
                        Server_Public_Data.tempCaraNbConfig=new Server_Public_MsgBox.CaraNb_Config(Server_Public_MsgBox.msgBox_Server_CaraNb_Config.poll());
                    }
                }
                Server_Public_MsgBox.refreshScreen();//本身已经是synchronized的了
                if(!Server_Public_MsgBox.msgBox_Server_Previous_Step.poll().equals(null)){
                    Server_Public_Thread.tServerNewGame.resumeT();//唤醒上一步
                    this.suspendT();
                }else if(!Server_Public_MsgBox.msgBox_Server_Next_Step.poll().equals(null)){
                    Server_Public_Thread.tServerCaraSelect.resumeT();//唤醒下一步
                    this.suspendT();
                }
            }
        }
         /**----End-----**/
    }

    public void stopT(){
        synchronized(this){
            this.stop=true;
        }
    }

    public void suspendT(){
        synchronized(this){
            this.suspend=true;
        }
    }

    public void resumeT(){
        synchronized(this){
            this.suspend=false;
        }
    }

    public void refreshScreen_NbCaraConfig(int nbPlayer){
        synchronized(Server_Public_Data.semaCaraNb_Config_Selections){
            Server_Public_Data.caraNb_Config_Selections=new ArrayList<Server_Public_MsgBox.CaraNb_Config>();//重置选项
            Server_Public_MsgBox.CaraNb_Config tempCongif;//构造函数 nbLoyal nbRebel nbSpy
            if(nbPlayer==4){
                tempCongif=new Server_Public_MsgBox.CaraNb_Config(1, 1, 1);//注意这里CaraNb_Config是个静态类
                Server_Public_Data.caraNb_Config_Selections.add(tempCongif);
                tempCongif=new Server_Public_MsgBox.CaraNb_Config(1, 2, 0);//注意这里CaraNb_Config是个静态类
                Server_Public_Data.caraNb_Config_Selections.add(tempCongif);
            }else if(nbPlayer==5){
                tempCongif=new Server_Public_MsgBox.CaraNb_Config(1, 2, 1);//注意这里CaraNb_Config是个静态类
                Server_Public_Data.caraNb_Config_Selections.add(tempCongif);
            }else if(nbPlayer==6){
                tempCongif=new Server_Public_MsgBox.CaraNb_Config(1, 3, 1);//注意这里CaraNb_Config是个静态类
                Server_Public_Data.caraNb_Config_Selections.add(tempCongif);
                tempCongif=new Server_Public_MsgBox.CaraNb_Config(1, 2, 2);//注意这里CaraNb_Config是个静态类
                Server_Public_Data.caraNb_Config_Selections.add(tempCongif);
                tempCongif=new Server_Public_MsgBox.CaraNb_Config(2, 3, 0);//注意这里CaraNb_Config是个静态类
                Server_Public_Data.caraNb_Config_Selections.add(tempCongif);
            }else if(nbPlayer==7){
                tempCongif=new Server_Public_MsgBox.CaraNb_Config(2, 3, 1);//注意这里CaraNb_Config是个静态类
                Server_Public_Data.caraNb_Config_Selections.add(tempCongif);
            }else if(nbPlayer==8){
                tempCongif=new Server_Public_MsgBox.CaraNb_Config(2, 4, 1);//注意这里CaraNb_Config是个静态类
                Server_Public_Data.caraNb_Config_Selections.add(tempCongif);
                tempCongif=new Server_Public_MsgBox.CaraNb_Config(3, 4, 0);//注意这里CaraNb_Config是个静态类
                Server_Public_Data.caraNb_Config_Selections.add(tempCongif);
                tempCongif=new Server_Public_MsgBox.CaraNb_Config(2, 3, 2);//注意这里CaraNb_Config是个静态类
                Server_Public_Data.caraNb_Config_Selections.add(tempCongif);
            }else if(nbPlayer==9){
                tempCongif=new Server_Public_MsgBox.CaraNb_Config(3, 4, 1);//注意这里CaraNb_Config是个静态类
                Server_Public_Data.caraNb_Config_Selections.add(tempCongif);
            }else if(nbPlayer==10){
                tempCongif=new Server_Public_MsgBox.CaraNb_Config(3, 4, 2);//注意这里CaraNb_Config是个静态类
                Server_Public_Data.caraNb_Config_Selections.add(tempCongif);
            }
        //?????????????????????显示
        }
    }
/*----------Private functions-----------*/
/*----------Constructor-----------------*/
    public T_Server_CaraNb_Config() {
        synchronized(this){
            this.stop=false;
            this.suspend=true;//一开始是悬停的，直到被T_Server_New_Game唤醒
        }
    }
/*----------Gets and sets---------------*/
}
